//
//  HLFriendViewController.m
//  YueYue
//
//  Created by hulu001 on 2023/6/1.
//

#import "HLFriendViewController.h"
#import <JXCategoryView/JXCategoryView.h>
#import "HLFriendListViewController.h"

@interface HLFriendViewController ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic, strong) NSArray <NSString *>*titles;
@property (nonatomic, strong) NSArray *types;
@property (nonatomic, assign) NSInteger defautIndex;
@property (nonatomic, strong) HLUserInfoModel *user;

@end

@implementation HLFriendViewController

- (instancetype)initWithListType:(HLFriendType)listType user:(HLUserInfoModel *)user
{
    self = [super init];
    if (self){
        self.user = user;
        NSInteger defautIndex = 0;
        switch (listType) {
            case HLFriendTypeFans:
                defautIndex = 2;
                break;
            case HLFriendTypeAttention:
                defautIndex = 0;
                break;
            case HLFriendTypeMine:
                defautIndex = 1;
                break;
                
            default:
                break;
        }
        
        self.defautIndex = defautIndex;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.types = @[@(HLFriendTypeAttention), @(HLFriendTypeMine), @(HLFriendTypeFans)];
}
- (void)setupNavigationItems
{
    [super setupNavigationItems];
    self.title = @"发现新朋友";
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDarkContent;
}

- (UIImage *)qmui_navigationBarBackgroundImage
{
    return [UIImage qmui_imageWithColor:UIColorWhite];
}

- (nullable UIColor *)qmui_navigationBarTintColor
{
    return UIColorBlack;
}


- (void)initSubviews
{
    [super initSubviews];
 
    self.titles = @[[NSString stringWithFormat:@"关注 %@", _user.myFollowCount], [NSString stringWithFormat:@"好友 %@", _user.myFriendCount], [NSString stringWithFormat:@"粉丝 %@", _user.myFansCount]];
    
    self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectZero];
    self.categoryView.delegate = self;
    self.categoryView.titleColor = HLTextColor3;
    self.categoryView.titleSelectedColor = HLTextColor1;
    self.categoryView.titleFont = UIFontMediumMake(15);
    self.categoryView.titleSelectedFont = UIFontMediumMake(15);
    self.categoryView.averageCellSpacingEnabled = YES;
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.titleLabelZoomEnabled = YES;
    self.categoryView.titleLabelZoomScale = 1.0;
    self.categoryView.titleLabelStrokeWidthEnabled = YES;
    self.categoryView.backgroundColor = UIColorClear;
    self.categoryView.titles = self.titles;
    self.categoryView.defaultSelectedIndex = self.defautIndex;
    [self.view addSubview:self.categoryView];
    
    [_categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(38);
        make.top.mas_equalTo(NavigationContentTopConstant + 4);
    }];
    
    self.categoryView.titleColorGradientEnabled = YES;
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = UIColorClear;
    lineView.indicatorHeight = 5.f;
    lineView.indicatorWidth = 12.f;
    lineView.indicatorCornerRadius = 1.5f;
    lineView.verticalMargin = 2;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_Lengthen;
    UIImageView *bottom = [[UIImageView alloc] initWithImage:UIImageMake(@"tag_bottom")];
    [lineView addSubview:bottom];
    [bottom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    self.categoryView.indicators = @[lineView];

    
    
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    [self.view addSubview:self.listContainerView];
    [_listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.top.equalTo(_categoryView.mas_bottom).offset(2);
    }];
    
    self.categoryView.listContainer = self.listContainerView;
    
    
}


#pragma mark - JXCategoryViewDelegate

// 返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}
// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    HLFriendType type = [self.types[index] integerValue];
    HLFriendListViewController *listVC = [[HLFriendListViewController alloc] initWithListType:type];
    return listVC;

}


@end
